﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;

namespace T5tk1
{
    class DBHelper
    {
        public string sqlStr;

        public static string conStr = "server=.;database=Login1;Integrated Security=true";

        public static SqlConnection conn = null;

        public static void InitConnection()
        {
            if (conn==null)
            {
                conn = new SqlConnection(conStr);
            }
            
        }
        //查询
        public static SqlDataReader GetDataReader(string sqlStr)
        {
            InitConnection();
            //SqlConnection conn = new SqlConnection(sqlStr);
            conn.Open();
            SqlCommand cmd = new SqlCommand(sqlStr, conn);
            
            return cmd.ExecuteReader(CommandBehavior.CloseConnection);
        }
        //添加
        public static bool ExecuteNonQuery(string sqlStr)
        {
            InitConnection();
            SqlCommand cmd = new SqlCommand(sqlStr, conn);
            conn.Open();
            int result = cmd.ExecuteNonQuery();
            conn.Close();
            return result > 0;
        }
    }
}
